/**
 * Copyright 2008 Matthew DeLambo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.delambo.drool.interfaces;

import com.delambo.drool.pooling.*;
import com.delambo.drool.exceptions.DroolException;
import java.util.*;
import java.sql.*;

/**
 *
 * @author delambo
 */
public interface Drool<ID, POOL extends Pool> {
    
    interface Factory<ID, POOL extends Pool> {
        Drool<ID, POOL> create(String logPropsFile, String poolPropsFile, ID id) 
                throws DroolException;
        Drool<ID, POOL> create(String logPropsFile, HashMap p) throws DroolException;
    }
    
    /**
     * Gets a connection from the pool with the given identifier.
     * @param id identifier for pool to grab connection from.
     * @return pooled connection.
     */
    Connection getConnection(ID id) throws DroolException;
    
    /**
     * Returns a connection to the pool with the given identifier.
     * @param id identifier of pool to return to.
     * @param con borrowed connection.
     */
    public void returnConnection(ID id, Connection con) throws DroolException;
    
    /**
     * Closes the given pool in the pools map.
     * @param id identifier of pool to close.
     */
    public void closePool(ID id) throws DroolException;
    
    /**
     * Closes all of the pools in the pools map.
     */
    public void closeAllPools();
    
    /**
     * Prints the current state of the pool with the given identifier to the 
     * pool log.
     * @param id
     * @param location
     */
    public void printState(ID id, String location) throws DroolException;
}
